package mahjong;

import java.util.Comparator;

/** A comparator used to determine the reletive order in which the tiles
 * should be printed so that tiles can be printed more closedly together.
 */
public class PaintOrderComparator implements Comparator<Tile>
{
	/** Comparator interface method.
	 * @param t1 first tile to be compared.
	 * @param t2 second tile to be compared.
	 * @return -1, 0 or 1.
	 */
	public int compare(Tile t1, Tile t2)
	{
		if (t1.getZ() < t2.getZ()) return -1;
		if (t1.getZ() > t2.getZ()) return 1;
		if (t1.getY() - t2.getY() > 1) return 1;
		if (t1.getY() - t2.getY() < -1) return -1;
		if (t1.getX() - t2.getX() > 1) return -1;
		if (t1.getX() - t2.getX() < -1) return 1;

		return 0;
	}
}
